/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.crud.patient.patientComponents.controller;

import systole.domain.persons.Patient;
import systole.exceptions.ExceptionDAO;
import systole.view.crud.controller.ControllerEntityEdition;
import systole.view.utils.ErrorDialog;

/**
 *
 * @author jmj
 */
public abstract class ControllerEditionPatienComponent extends ControllerEntityEdition {

    protected Patient patient;

    /**
     * @param patient
     */
    public ControllerEditionPatienComponent(Patient patient) {
        super();
        this.patient = patient;
    }

    /**
     * method to confirm operation
     */
    @Override
    public void ok() {
        String msg = this.valid();
        if (msg == null) {
            try {
                this.loadEntityFromForm();
                this.editForm.setVisible(false);
                this.editForm.dispose();
                this.save();
                this.setChangesCommitted(true);
            } catch (ExceptionDAO ex) {
                this.facadeDB.rollbackTransaction();
                ErrorDialog.showError(this.editForm,ex.getMessage());
            }
        } else {
           ErrorDialog.showError(this.editForm,msg);
        }
    }

    /**
     * method to cancel operation
     */
    @Override
    public void cancel() {
        this.editForm.setVisible(false);
        this.setChangesCommitted(false);
        this.editForm.dispose();
    }
}
